/*
 * file name:module_fs.h
 * version :v1.0.0
 * Change Logs:
 * Date             Author          main change
 * 2024-08-21       lanxin          the first version
 *
*/

/********************************************* READ ME BEGIN *************************************************************/

/* Brief:
 *
 * * 1.RTT 文件系统封装接口。
 *
*/

/********************************************* READ ME END ***************************************************************/

#ifndef _module_fs_H
#define _module_fs_H

/* source file */
#include "dfs_fs.h"
#include <stdio.h>
#include "unistd.h"

/* public define */
#define ENABLE_REMOUNT //挂载失败后进行格式化在尝试一次挂载

#define ENABLE_ROM_FS_API //need enable romfs
#define ENABLE_RAM_FS_API //need drv_ramdisk.c
#define ENABLE_FAL_FS_API //need fal

#define Max_Read_Size_OneTime   	8192//fs_read_all 一次读取最大文件
#define Max_ReadBack_Size_OneTime	8192//fs_write_data_check 每次回读的字节数
#define Max_Copy_File_FIFO_SIZE		8192//fs_copy_file 每次拷贝的字节数

#ifdef ENABLE_RAM_FS_API
	#define RAM_DISK_BLOCK_SIZE     4096u
	#include "drv_ramdisk.h"
#endif

#ifdef ENABLE_FAL_FS_API
	#include "fal.h"
#endif

#ifdef ENABLE_ROM_FS_API
	#include "dfs_romfs.h"
#endif

/* variable typedef */
typedef void ( *fs_event_cb_t ) ( int event, void *para );

/* fs event */
enum
{
	E_FS_EVENT_CREATE_FILE_FAILED = 0x00,
	E_FS_EVENT_WRITE_FAILED,
	E_FS_EVENT_READ_FAILED,
	E_FS_EVENT_DELETE_FAILED,
	E_FS_EVENT_CHECK_FAILED,
};

/* function typedef */

/* variable declaration for other to use */

/* function declaration for other to use */
int fs_prepare ( void );
int fs_lock ( uint32_t time );
int fs_unlock ( void );
void fs_set_event_cb ( fs_event_cb_t cb );
void fs_clear_event_cb ( void );

int fs_mount ( const char *dev_name, const char *path, const char *fs_type );

#ifdef ENABLE_RAM_FS_API
	int fs_mount_at_ram ( const char *dev_name, const char *path, const char *fs_name, uint32_t size_byte );
#endif

#ifdef ENABLE_ROM_FS_API
	int fs_mount_at_rom ( const char *path, const void *data );
#endif

#ifdef ENABLE_FAL_FS_API
	int fs_mount_at_fal_partition ( const char *part_name, const char *path, const char *fs_type );
#endif

int fs_unmount ( const char *path );
int fs_mkfs ( const char *dev_name, const char *fs_name );

int fs_delete_file ( const char *path );
int fs_delete_dir_file ( const char *path, uint8_t del_dir );

int fs_create_dir ( const char *path );
int fs_create_dir_by_file_path ( const char *path );
int fs_create_file ( const char *path );

ssize_t fs_write ( const char *path, ssize_t offset, const void *buf, ssize_t len );
ssize_t fs_write_with_create ( const char *path, ssize_t offset, const void *buf, ssize_t len );
ssize_t fs_write_append ( const char *path, const void *buf, ssize_t len );
ssize_t fs_write_O_WRONLY_O_TRUNC ( const char *path, const void *buf, ssize_t len );
int fs_write_data_check ( const char *path, ssize_t offset, const void *p_write, ssize_t len );

ssize_t fs_read ( const char *path, ssize_t offset, void *buf, ssize_t len );
ssize_t fs_read_all ( const char *path, char **buf );

int fs_copy_file ( const char *dst_dir, const char *src_dir, const char *file_name );
int fs_copy_dir_file ( const char *dst_dir, const char *src_dir );

int fs_get_file_access ( const char *path );
int fs_get_dir_exist ( const char *path );
int fs_get_dir_file_exist ( const char *path );
int fs_get_capacity ( const char *path );
ssize_t fs_get_file_size ( const char *path );
int fs_get_dir_file_num ( const char *path );

#endif /* _module_fs_H */
